package l.l.w.Offer.ReverseListDemo;

/**
 * Created by llw on 2017/9/8.
 */
class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
public class ReverseListDemo {
    public static ListNode ReverseList(ListNode head) {
        if (head == null) return null;
        ListNode pre;
        ListNode curr = head.next;
        pre = head;
        pre.next = null;
        while (curr != null) {
            ListNode node = curr.next;
            curr.next=pre;
            pre=curr;
            curr = node;

        }
        return pre;
    }
    public static void main(String[] args){
        ListNode head  = new ListNode(0);
        ListNode curr,temp;
        curr = head;
        for (int i = 1; i < 3; i++) {
            temp = new ListNode(i);
            curr.next = temp;
            curr = curr.next;
        }
        ListNode result ;
        result = ReverseList(head);
        while (result != null) {
            System.out.print(result.val+"  ");
            result = result.next;
        }

    }

}
